package com.capybara.account.controller;

import com.capybara.account.result.Result;
import com.capybara.account.result.ResultSet;
import com.capybara.account.service.IFileService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

/**
 * 文件控制器
 *
 * @author guochaowang
 * {@code @date} 2022/07/18
 */
@Slf4j
@RestController
@AllArgsConstructor
@RequestMapping("/evoaccount/file")
public class LocalFileController {
    private final IFileService iFileService;

    /**
     * 上传获取路径
     *
     * @param file 上传路径
     * @return 文件路径
     */
    @PostMapping("uploadToUrl")
    public Result<?> fileUploadUrl(@RequestParam("file") MultipartFile file,
                                   @RequestParam("type") String type) throws IOException {
        String obj = iFileService.putLocalFile(file, type);
        return ResultSet.go(obj);
    }


}
